package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.hencoder.hencoderpracticedraw1.R;

public class Practice9DrawPathView extends View {

    private Path mPath;
    private Paint mPaint;

    public Practice9DrawPathView(Context context) {
        super(context);
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint();
        mPath = new Path();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mPath.addArc(getResources().getDimensionPixelOffset(R.dimen.x120),
                    getResources().getDimensionPixelOffset(R.dimen.x120),
                    getResources().getDimensionPixelOffset(R.dimen.x250),
                    getResources().getDimensionPixelOffset(R.dimen.x250),
                    -getResources().getDimensionPixelOffset(R.dimen.x225),
                    getResources().getDimensionPixelOffset(R.dimen.x225));
            mPath.arcTo(getResources().getDimensionPixelOffset(R.dimen.x250),
                    getResources().getDimensionPixelOffset(R.dimen.x120),
                    getResources().getDimensionPixelOffset(R.dimen.x370),
                    getResources().getDimensionPixelOffset(R.dimen.x250),
                    -getResources().getDimensionPixelOffset(R.dimen.x180),
                    getResources().getDimensionPixelOffset(R.dimen.x225), false);
            mPath.lineTo(getResources().getDimensionPixelOffset(R.dimen.x250),
                    getResources().getDimensionPixelOffset(R.dimen.x350));
        }
    }

    public Practice9DrawPathView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容：使用 canvas.drawPath() 方法画心形
        canvas.drawPath(mPath, mPaint);
    }
}
